#ifndef SERVER_H
#define SERVER_H

#include <QObject>
#include <QProtobufSerializer>
#include <QWebSocketServer>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QHttpServer>
#include <QTcpServer>
#include "base.qpb.h"
#include "friend.qpb.h"
#include "gateway.qpb.h"
#include "message_storage.qpb.h"
#include "message_transmit.qpb.h"
#include "notify.qpb.h"
#include "file.qpb.h"
#include "speech_recognition.qpb.h"
#include "user.qpb.h"
#include <QFileInfo>
#include <QFile>
#include <QPixmap>
#include <QIcon>

class HttpServer : public QObject
{
    Q_OBJECT
public:
    static HttpServer* getInstance();
    bool initHttpServer();

    //////////////////////////////////////////////////////////////
    /// 配置路由相关函数
    /// //////////////////////////////////////////////////////////
    /// 获取个人用户信息
    QHttpServerResponse getUserInfo(const QHttpServerRequest &req);
    /// 获取好友列表
    QHttpServerResponse getFriendList(const QHttpServerRequest &req);
    /// 获取会话列表
    QHttpServerResponse getChatSessionList(const QHttpServerRequest &req);
    /// 获取好友申请列表
    QHttpServerResponse getApplyList(const QHttpServerRequest &req);
    /// 获取最近消息列表
    QHttpServerResponse getRecent(const QHttpServerRequest &req);
    /// 发送信息
    QHttpServerResponse newMessage(const QHttpServerRequest &req);

    /// 修改昵称
    QHttpServerResponse setNickname(const QHttpServerRequest &req);
    /// 修改签名
    QHttpServerResponse setDesc(const QHttpServerRequest &req);
    /// 获取验证码
    QHttpServerResponse getVerifyCode(const QHttpServerRequest &req);
    /// 修改电话号
    QHttpServerResponse setPhone(const QHttpServerRequest &req);
    /// 修改头像
    QHttpServerResponse setAvatar(const QHttpServerRequest &req);
    /// 删除好友
    QHttpServerResponse removeFriend(const QHttpServerRequest &req);
    /// 申请好友
    QHttpServerResponse addFriendApply(const QHttpServerRequest &req);
    /// 好友申请同意/拒绝
    QHttpServerResponse addFriendProcess(const QHttpServerRequest &req);
    /// 创建群聊会话
    QHttpServerResponse createChatSession(const QHttpServerRequest &req);
    /// 获取消息会话成员列表
    QHttpServerResponse getChatSessionMember(const QHttpServerRequest &req);
    /// 搜索好友结果
    QHttpServerResponse searchFriend(const QHttpServerRequest &req);
    /// 通过关键词搜索历史消息
    QHttpServerResponse searchHistory(const QHttpServerRequest &req);
    /// 通过时间获取历史消息
    QHttpServerResponse getHistory(const QHttpServerRequest &req);
    /// 通过用户密码进行登录
    QHttpServerResponse usernameLogin(const QHttpServerRequest &req);
    /// 通过用户密码进行注册
    QHttpServerResponse usernameRegister(const QHttpServerRequest &req);
    /// 通过电话进行登录
    QHttpServerResponse phoneLogin(const QHttpServerRequest &req);
    /// 通过电话进行注册
    QHttpServerResponse phoneRegister(const QHttpServerRequest &req);
    /// 获取文件内容
    QHttpServerResponse getSingleFile(const QHttpServerRequest &req);
    /// 语音转文字
    QHttpServerResponse recognition(const QHttpServerRequest &req);

private:
    //单例模式
    HttpServer(){};
    static HttpServer* instance;

    //序列化器
    QProtobufSerializer pbSerializer;
    //HTTP服务器
    QHttpServer httpServer;
    QTcpServer tcpServer;

signals:
};

class WebSocketServer : public QObject
{
    Q_OBJECT
public:
    static WebSocketServer* getInstance();
    bool initWebSocketServer();
private:
    //单例模式
   WebSocketServer() : webSocketServer("Qt WebSocket Server",QWebSocketServer::NonSecureMode){}

    static WebSocketServer* instance;

    //序列化器
    QProtobufSerializer pbSerializer;
    //WebSocket服务器
    QWebSocketServer webSocketServer;

    //测试接收message的变量--count,代表测试数据下标
    int messageIndex = 0;

    //测试删除好友的变量
    int deleteOfUserId = 0;

signals:
    //测试 接收消息 按钮的 发送文本消息 信号
    void sendTextResp();
    void sendImageResp();
    void sendFileResp();
    void sendSpeechResp();

    //测试 删除好友 按钮的信号
    void sendFriendRemove();
    //测试 发送好友申请 按钮的信号
    void sendAddFriendApply();
    //测试 好友申请同意/拒绝 按钮的信号
    void sendAddFriendProcess(bool);
    //测试 创建群聊会话 按钮的信号
    void sendCreateChatSession();

};

#endif // SERVER_H
